home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include "defs.h"
-
- #define BLACK 0
- #define DEG2RAD (M_PI/180.)
-
- har *progname;
- har *filename;
- ixrect *pr1, *pr2;
-
- #ifdef STANDALONE
- ain(argc, argv, envp)
- #else
- ough_main(argc, argv, envp)
- #endif
- int argc;
- char **argv;
- char **envp;
- {
- register int i, j;
- int levels;
- Pixrect *hough();
-
- progname = strsave(argv[0]);
- parse_profile(&argc, argv, envp);
-
- while ((gc = getopt(argc, argv, " ")) != EOF)
- switch (gc) {
- case '?':
- errflag++;
- break;
- }
-
- if (errflag)
- error((char *) 0, "Usage: %s: [infile] [outfile]\n", progname);
-
- for (stream = 0; optind < argc; stream++, optind++)
- if (stream < 2 && strcmp(argv[optind], "-") != 0)
- if (freopen(argv[optind], mode[stream], f[stream]) == NULL)
- error("%s %s", PR_IO_ERR_INFILE, argv[optind]);
-
- if ((pr1 = pr_load(stdin, NULL)) == NULL)
- error(PR_IO_ERR_RASREAD);
-
- if (pr1->pr_depth != 1)
- error("Input image must be 1 bit deep");
-
- pr2 = hough(pr1);
-
- pr_dump(pr2, stdout, NULL, RT_STANDARD, 0);
- }
-
-
-
- ixrect *hough (pr)
- ixrect *pr;
- {
- double sqrt (); /* square root function */
- Pixrect *hp; /* new image for hough transformation */
- int xoff, yoff; /* centre image = origin hough space */
- register int r, theta; /* coords in hough space */
- register int x, y; /* coords in image */
- int maxr; /* max val of r possible for image */
- int c[180], s[180]; /* lookup tables for cos and sin */
-
- /* initialise variables */
-
- xoff = pr->pr_size.x/2;
- yoff = pr->pr_size.y/2;
- maxr = (int) (sqrt ((double) (pr->pr_size.x * pr->pr_size.x + pr->pr_size.y * pr->pr_size.y)) / 2);
-
- for (theta = 0; theta < 180; theta++) {
- c[theta] = (int) (cos (DEG2RAD * theta) * 1000);
- s[theta] = (int) (sin (DEG2RAD * theta) * 1000);
- }
-
- /* create new image */
-
- if ((hp = mem_create (180, 2 * maxr + 1, 8)) == NULL)
- error("mem_create returned NULL");
-
- for (r = 0; r < 2 * maxr + 1; r++)
- for (theta = 0; theta < 180; theta++)
- pr_put(hp, theta, r, 0);
-
- /* step through image */
-
- for (y = 0; y < pr->pr_size.y; y++)
- for (x = 0; x < pr->pr_size.x; x++)
- if (pr_get(pr, x,y) == BLACK)
- for (theta = 0; theta < 180; ++theta) {
- r = (y - yoff) * s[theta] - (x - xoff) * c[theta];
- r = r < 0 ? r / 1000 : r / 1000 + 1;
- pr_put(hp, theta, maxr + r, pr_get(hp, theta, maxr + r) +1);
- }
-
- return (hp);
- }
-
-